package com.dxt.service;

import com.alibaba.fastjson.JSONObject;
import com.dxt.common.MyBusiException;
import com.dxt.message.AppRequestMessage;
import com.dxt.message.ReponseMessage;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public abstract class IBaseBusiService {
    private HttpServletRequest request;
    private HttpServletResponse response;
    private AppRequestMessage msg;

    abstract public ReponseMessage execute(String reqInfo, String source);

    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    public void setResponse(HttpServletResponse response) {
        this.response = response;
    }

    public AppRequestMessage getMsg() {
        return msg;
    }

    public void setMsg(AppRequestMessage msg) {
        this.msg = msg;
    }

    protected void checkParams(JSONObject jsonObject, String... args) throws MyBusiException {
        for (String param : args) {
            if (null == jsonObject.getString(param) || "".equals(jsonObject.getString(param))) {
                throw new MyBusiException("参数" + param + "不可为空！");
            }
        }
    }

}
